package com.wages.project.system.dissent.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wages.framework.aspectj.lang.annotation.Log;
import com.wages.framework.aspectj.lang.enums.BusinessType;
import com.wages.project.system.dissent.domain.Dissent;
import com.wages.project.system.dissent.service.IDissentService;
import com.wages.framework.web.controller.BaseController;
import com.wages.framework.web.domain.AjaxResult;
import com.wages.common.utils.poi.ExcelUtil;
import com.wages.framework.web.page.TableDataInfo;

/**
 * 异议信息Controller
 *
 * @author wages
 * @date 2021-02-08
 */
@Controller
@RequestMapping("/system/dissent")
public class DissentController extends BaseController
{
    private String prefix = "system/dissent";

    @Autowired
    private IDissentService dissentService;

    @RequiresPermissions("system:dissent:view")
    @GetMapping()
    public String dissent()
    {
        return prefix + "/dissent";
    }

    /**
     * 查询异议信息列表
     */
    @RequiresPermissions("system:dissent:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Dissent dissent)
    {
        startPage();
        List<Dissent> list = dissentService.selectDissentList(dissent);
        return getDataTable(list);
    }

    /**
     * 导出异议信息列表
     */
    @RequiresPermissions("system:dissent:export")
    @Log(title = "异议信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Dissent dissent)
    {
        List<Dissent> list = dissentService.selectDissentList(dissent);
        ExcelUtil<Dissent> util = new ExcelUtil<Dissent>(Dissent.class);
        return util.exportExcel(list, "dissent");
    }

    /**
     * 新增异议信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存异议信息
     */
    @RequiresPermissions("system:dissent:add")
    @Log(title = "异议信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Dissent dissent)
    {
        return toAjax(dissentService.insertDissent(dissent));
    }

    @Log(title = "异议信息", businessType = BusinessType.INSERT)
    @PostMapping("/add1")
    @ResponseBody
    public AjaxResult addSave1(Dissent dissent)
    {
        dissent.setUid(getUserId());
        dissent.setStatus("N");
        return toAjax(dissentService.insertDissent(dissent));
    }

    /**
     * 修改异议信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Dissent dissent = dissentService.selectDissentById(id);
        mmap.put("dissent", dissent);
        return prefix + "/edit";
    }

    /**
     * 修改保存异议信息
     */
    @RequiresPermissions("system:dissent:edit")
    @Log(title = "异议信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Dissent dissent)
    {
        return toAjax(dissentService.updateDissent(dissent));
    }

    /**
     * 删除异议信息
     */
    @RequiresPermissions("system:dissent:remove")
    @Log(title = "异议信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dissentService.deleteDissentByIds(ids));
    }
}
